﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MJM.SCA.EntidadesNegocio;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
using MJM.SPP.EntidadesNegocio;
using MJM.Principal;

namespace wRegPadron.frmOpciones
{
    public partial class ucListaIncidencias : System.Web.UI.UserControl
    {
        protected static List<GraficoEN> lstIncidencias = new List<GraficoEN>();

        private void openWindow(string _windowName)
        {
            ClientScriptManager _cs = Page.ClientScript;
            string ClientScript = "<script type=\"text/javascript\">window.open('" + _windowName + "', 'Invoice', " + "' menubar=0, resizable=1,scrollbars=1,width=1150,height=700')</script>";
            if (!_cs.IsStartupScriptRegistered("WOpen"))
            {
                _cs.RegisterStartupScript(typeof(Page), "abrir", ClientScript);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bdtFechaIni.SelectedDate = DateTime.Now;
                bdtFechaFin.SelectedDate = DateTime.Now;
                SubOpcionEN objSubOpcionEN = MediadorCN.GetSubOpcion().ObtenerTexto("MenuListaInci");
                lblTitulo.Text = objSubOpcionEN.SUBOPT_chNOMSOP;
                lblDescripcion.Text = objSubOpcionEN.SUBOPT_chDESSOP;
                //pTabla.Visible = false;
            }
        }

        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            string ini, fin;
            string mes = bdtFechaIni.SelectedDate.Month.ToString();
            string dia = bdtFechaIni.SelectedDate.Day.ToString();
            if (mes.Length < 2)
                mes = "0" + mes;
            if (dia.Length < 2)
                dia = "0" + dia;
            ini = bdtFechaIni.SelectedDate.Year.ToString() + mes + dia;
            mes = bdtFechaFin.SelectedDate.Month.ToString();
            dia = bdtFechaFin.SelectedDate.Day.ToString();
            if (mes.Length < 2)
                mes = "0" + mes;
            if (dia.Length < 2)
                dia = "0" + dia;
            fin = bdtFechaFin.SelectedDate.Year.ToString() + mes + dia;
            lstIncidencias = MediadorCN.GetGrafico().ListarCantidadIncidencia(ini, fin);
            gvIncidentes.DataSource = lstIncidencias;
            gvIncidentes.DataBind();
        }

        protected void gvIncidentes_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "VerIncidentes")
            {
                int index = 0;
                string nombre = "";
                index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvIncidentes.Rows[index];
                index = Convert.ToInt32(Server.HtmlDecode(row.Cells[0].Text).ToString());
                nombre = Server.HtmlDecode(row.Cells[1].Text).ToString();
                string inicio = bdtFechaIni.SelectedDate.Year + (bdtFechaIni.SelectedDate.Month + 100).ToString().Substring(1, 2) + (bdtFechaIni.SelectedDate.Day + 100).ToString().Substring(1, 2);
                string fin = bdtFechaFin.SelectedDate.Year + (bdtFechaFin.SelectedDate.Month + 100).ToString().Substring(1, 2) + (bdtFechaFin.SelectedDate.Day + 100).ToString().Substring(1, 2);
                Session.Add("datos", index.ToString() + "," + nombre + "," + inicio + "," + fin);
                openWindow("frmIncidencias.aspx");
                //openWindow("www.desarrolloweb.com/articulos/18.php");
            }
        }

        protected void gvIncidentes_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvIncidentes.PageIndex = e.NewPageIndex;
            gvIncidentes.DataSource = lstIncidencias;
            gvIncidentes.DataBind();
        }


    }
}